import { message } from 'antd'
import { onlyView, exportImg, reloadSettings } from './draw'
import store from '../redux/store'
import { setDrawWin } from '../redux/action/drawActions'
import { toggleMagneticPoint } from '../redux/action/canvasActions'

function newFile() {
	if (window.confirm('这一步将会清空所有目前进度，是否清除？')) {
		store.dispatch({ type: 'RESET_STORE' })
		reloadSettings()
	}
}
function openFile() {
	message.info('developing...')
}
function backToOldVersion() {
	window.location.href = 'https://sj-261725.github.io/module/MTPP_v2.0.html'
}
function downloadImg() {
	const data = exportImg()
	const saveLink = document.createElement('a')
	saveLink.href = data
	saveLink.download = 'mtpp.png'
	saveLink.click()
}

const globalTools = [
	{
		text: '新建',
		func: newFile,
	},
	{
		text: '打开',
		func: openFile,
	},
	{
		text: '导出',
		isNav: true,
		childrenItems: [
			{
				text: '图片格式',
				func: downloadImg,
			},
			{
				text: '工程文件',
				func: openFile,
			},
		],
	},
	{
		text: '设置',
		func: openFile,
	},
	{
		text: '帮助',
		func: openFile,
	},
	{
		text: '回到旧版',
		func: backToOldVersion,
	},
]
const funcTools = [
	{
		text: '一次函数',
		func: store.dispatch.bind(this, setDrawWin('func', 1)),
	},
	{
		text: '二次函数',
		isNav: true,
		childrenItems: [
			{
				text: '一般式',
				func: store.dispatch.bind(this, setDrawWin('func', 2)),
			},
			{
				text: '顶点式',
				func: store.dispatch.bind(this, setDrawWin('func', -4)),
			},
		],
	},
	{
		text: '反比例函数',
		func: store.dispatch.bind(this, setDrawWin('func', -1)),
	},
	{
		text: 'sin 函数',
		func: store.dispatch.bind(this, setDrawWin('func', -2)),
	},
	{
		text: 'cos 函数',
		func: store.dispatch.bind(this, setDrawWin('func', -3)),
	},
	{
		text: '自定义函数',
		func: store.dispatch.bind(this, setDrawWin('func', 0)),
	},
]
const graphTools = [
	{
		text: '圆',
		func: store.dispatch.bind(this, setDrawWin('graph', 0)),
	},
	{
		text: '弧',
		func: store.dispatch.bind(this, setDrawWin('graph', 1)),
	},
]
const advancedTools = [
	{
		text: '终端',
		func: openFile,
	},
	{
		text: '只看',
		isNav: true,
		childrenItems: [
			{
				text: '禁用',
				func: onlyView.bind(this, 0),
			},
			{
				text: '第一象限',
				func: onlyView.bind(this, 1),
			},
			{
				text: '第二象限',
				func: onlyView.bind(this, 2),
			},
			{
				text: '第三象限',
				func: onlyView.bind(this, 3),
			},
			{
				text: '第四象限',
				func: onlyView.bind(this, 4),
			},
		],
	},
	{
		text: '磁性点',
		isNav: true,
		childrenItems: [
			{
				text: '开启',
				func: store.dispatch.bind(this, toggleMagneticPoint(true)),
			},
			{
				text: '关闭',
				func: store.dispatch.bind(this, toggleMagneticPoint(false)),
			},
		],
	},
	{
		text: '描点',
		func: openFile,
	},
	{
		text: '连线',
		func: openFile,
	},
	{
		text: '求解析式',
		func: openFile,
	},
]
export { globalTools, funcTools, graphTools, advancedTools }
